﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DingHeng.TransportationManagement.DataAccess;
using DingHeng.TransportationManagement.Entity;

namespace DingHeng.TransportationManagement.Business
{
    public class VehicleBiz
    {
        public Vehicle LoadByID(Guid id)
        {
            using (VehicleDataAccess vda = new VehicleDataAccess())
            {
                return vda.LoadByCondition(v => v.ID == id).FirstOrDefault();
            }
        }
        public List<VehicleInfo> LoadByActiveVehicleLicensePlateNo(string licensePlateNo)
        {
            using (VehicleInfoDataAccess vida = new VehicleInfoDataAccess())
            {
                IQueryable<VehicleInfo> vList = vida.LoadByCondition(v => v.IsActive == true && v.WorkYear == DateTime.Now.Year && v.WorkMonth == DateTime.Now.Month);
                if(!string.IsNullOrEmpty(licensePlateNo))
                {
                    vList.Where(v=>v.LicensePlateNo.Contains(licensePlateNo));
                }
                return vList.ToList();
            }
        }
        public VehicleInfo LoadByInfoID(Guid id)
        {
            using (VehicleInfoDataAccess vida = new VehicleInfoDataAccess())
            {
                return vida.LoadByCondition(v => v.VehicleID == id).FirstOrDefault();
            }
        }
        public int Save(Vehicle entity)
        {
            using (VehicleDataAccess vda = new VehicleDataAccess())
            {
                return vda.Save(entity);
            }
        }
        public bool Verify(VehicleDispatchForm entity)
        {
            //TODO:根据业务逻辑编写校验规则
            return true;
        }

    }
}
